<?php

namespace plugin\piecing\app\admin\controller;

use app\admin\controller\Curd;
use plugin\piecing\app\admin\service\PiecingActivityService;
use support\Request;

class GoodsController extends Curd
{

    /**
     * 拼团列表
     * @return \support\Response
     */
    public function index()
    {
        if (request()->isAjax()) {

            $param = request()->all();

            $seckillService = new PiecingActivityService();
            $res = $seckillService->getList($param);
            return $this->success($res);
        }
        return view('goods/index');
    }

    /**
     * 添加拼团商品
     * @return void
     */
    public  function add(){
        if(request()->isAjaxPost()){
            $param = request()->post();
            $piecingActivityService = new PiecingActivityService();
            $res = $piecingActivityService->addPiecingActivityGoods($param);
            return $this->success($res);
        }
    }
    /**
     * 编辑拼团商品
     * @return void
     */
    public  function  edit(){
        $piecingActivityService = new PiecingActivityService();
        if (request()->isAjaxPost()) {
            $param = request()->post();
            $res = $piecingActivityService->editSeckillGoods($param);
            return $this->success($res);
        }
        return $this->success($piecingActivityService->buildEditParam(request()->input('activity_id')));
    }

    /**
     * 删除秒杀商品
     */
    public function del(Request $request)
    {
        if (request()->isAjax()) {

            $id = $request->input('id');

            $seckillService = new PiecingActivityService();
            $res = $seckillService->delSeckill($id);
            return json($res);
        }
    }
}